import axios from 'axios'
import config from '@/config'

/**
 * Descrition Funkey Worker Task
 * Date 2012.02.27
 * @param data
 * @returns {AxiosPromise}
 */
/**
 * 提交单个ActionTask
 * @param model
 * @param id
 * @param actionName
 * @returns {AxiosPromise}
 */
export function submitAction(model, id, actionName){
  return axios({
    method: 'POST',
    url: config.serverURI + config.api.model_opt + model  + '/' + id+'/action/'+actionName,
    params: {}
  })
}

/**
 * 批量提交ActionTask
 * @param model
 * @param id
 * @param actionName
 * @returns {AxiosPromise}
 */
export function submitActions(model, actionName, datas){
  const _params = datas.map(item => {
    item.model =  model;
    item.action = actionName;
    return item;
  });
  const _items = {"items": _params};

  return axios({
    method: 'POST',
    url: config.serverURI + config.action_task_batch,
    params: _items
  })
}

